package com.zhuangwe.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 做定时任务配置，配置线程，使用不同线程执行任务，提升效率
 *
 * @author LeviCoder
 * @create 2019-01-30 14:38
 */
@Configuration
@EnableScheduling
@ComponentScan(basePackages = "com.zhuangwe.task")
public class TaskConfig implements SchedulingConfigurer
{

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    @Bean
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(100);
    }
}
